import Random

function unitCopy!(m, row, col, board)
    for r in 1:3
        for c in 1:3
            board[row * 3 + r][col * 3 + c] = m[r, c]
        end
    end
end

function main()
    board = [[0 for i in 1:9] for i in 1:9]
    mid = Random.shuffle([i for i in 1:9])
    m = [mid[1:3] mid[4:6] mid[7:9]]
    unitCopy!(m, 1, 1, board)
    mr1 = m[1, :] 
    mr2 = m[2, :]
    mr3 = m[3, :]
    mc1 = m[:, 1] 
    mc2 = m[:, 2]
    mc3 = m[:, 3]
    ml = [mr2 mr3 mr1]'
    unitCopy!(ml, 1, 0, board)
    mr = [mr3 mr1 mr2]'
    unitCopy!(mr, 1, 2, board)
    mu = [mc2 mc3 mc1]
    unitCopy!(mu, 0, 1, board)
    md = [mc3 mc1 mc2]
    unitCopy!(md, 2, 1, board)
    mlc1 = ml[:, 1]
    mlc2 = ml[:, 2]
    mlc3 = ml[:, 3]
    mlt = [mlc2 mlc3 mlc1]
    unitCopy!(mlt, 0, 0, board)
    mlb = [mlc3 mlc1 mlc2]
    unitCopy!(mlb, 2, 0, board)
    mrc1 = mr[:, 1]
    mrc2 = mr[:, 2]
    mrc3 = mr[:, 3]
    mrt = [mrc2 mrc3 mrc1]
    unitCopy!(mrt, 0, 2, board)
    mrb = [mrc3 mrc1 mrc2]
    unitCopy!(mrb, 2, 2, board)

    for i in 1:9
        println(board[i])
    end
end

main()